<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const properties = [
        "中华园,北京市,公寓",
        "华景苑,上海市,别墅",
        "新城市广场,深圳市,公寓",
        "雅居乐花园,广州市,别墅",
        "恒大城,广州市,公寓",
        "太阳花园,北京市,别墅",
      ];

      // const room = function (data) {
      //   const obj = {}
      //   const arr = data.map(item => item.split(','))
      //   // console.log(arr);

      //   arr.forEach(([quarters,,house]) => {
      //     if(obj[house]){
      //       obj[house].push(quarters)
      //     }else{
      //       obj[house]=[]
      //       obj[house].push(quarters)
      //     }
      //   })

      //   console.log(obj);
      // }


      // room(properties)

      const room = function (data) {
        const arr = data.map(item => item.split(',')).filter(item => item[`${item.length - 1}`] === '公寓')
        const arr2 = data.map(item => item.split(',')).filter(item => item[`${item.length - 1}`] === '别墅')
        // const res = arr.filter(item => item[2] === '公寓')
        // console.log(res);
        // console.log(arr);
        // console.log(arr2);
        const res = arr.map(([quarters,,house]) => quarters)
        const res2 = arr2.map(([quarters,,house]) => quarters)
        // console.log(res);
        const obj = {
            '公寓':res,
            '别墅':res2,
        }
        return obj
      }

      console.log(room(properties));

    </script>
  </body>
</html>
